package com.itheima.controller;

import com.itheima.domain.Account;
import com.itheima.service.AccountSercice;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import java.util.List;

@Controller
@RequestMapping("/user")
public class UserController {

    @Autowired
    private AccountSercice accountService;

    @RequestMapping(value = "/save")
    public String save(ModelAndView modelAndView, Account account){
        accountService.save (account);
        modelAndView.addObject ("msg","Add a new account has successed!");
        return "success";
    }

    @RequestMapping("findAll")
    public String findAll(Model model){
        List<Account> accountList = accountService.findAll ();
        model.addAttribute ("accountList",accountList);
        return "accountList";
    }
}
